C mathematical functions

C mathematical operations are a group of functions in the standard library of the C programming language implementing basic mathematical functions.[1][2] Most of the functions involve the use of floating point numbers. Different C standards provide different albeit backwards-compatible, sets of functions. C mathematical functions are inherited in C++.

Contents

Overview of functions

Most of the mathematical functions are placed in math.h header (cmath header in C++). The functions that operate on integers, such as abs, labs, div, and ldiv, are instead specified in the stdlib.h header (cstdlib header in C++).

Any functions that operate on angles use radians as the unit of angle.[1]

In C89, all functions accept only type double for the floating-point arguments. In C99, this limitation was fixed by introducing new sets of functions with f and l suffixes that work on float and long double arguments respectively.[3]

Exponential functions
Power functions
Trigonometric functions
Hyperbolic functions
Error and gamma functions
Nearest integer floating point operations
Floating point manipulation functions
Classification

Floating point environment

C99 adds several functions and types for fine-grained control of floating point computations.[3] The additional functions and types are defined in fenv.h header (cfenv in C++).

Complex numbers

C99 adds a new _Complex keyword that provides support for complex numbers. Any floating point type can be modified with _Complex. In that case, a variable of such type contains a pair of floating point numbers and in such a way defines a complex number. C++ does not provide complex numbers in backwards compatible way. As an alternative, std::complex can be used.

All operations on complex numbers are defined in complex.h header.

Basic operations
Exponentiation operations
Trigonometric operations
Hyperbolic operations

Type-generic functions

The header tgmath.h defines a type-generic macro for each mathematical function, so that the same function name can be used to call functions accepting different types of the arguments.

Random number generation

The header stdlib.h (cstdlib in C++) defines several functions that can be used for statistically random number generation[4]

References

  1. ^ a b ISO/IEC 9899:1999 specification. p. 212, § 7.12. http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1124.pdf. 
  2. ^ Prata, Stephen (2004). C primer plus. Sams Publishing. Appendix B, Section V: The Standard ANSI C Library with C99 Additions. ISBN 0-672-32696-5. 
  3. ^ a b Prata, Stephen (2004). C primer plus. Sams Publishing. Appendix B, Section VIII: C99 Numeric Computational Enhancements. ISBN 0-672-32696-5. 
  4. ^ "GNU C Library -- Mathematics". http://www.cs.utah.edu/dept/old/texinfo/glibc-manual-0.02/library_17.html. Retrieved 2 November 2011. 

External links